import instance from '../../utils/request'
export default {
  namespaced: true,
  state: {
    HousingList: [],
    total: 0,
    LeaseList: [],
    LeaseTotal: 0
  },
  mutations: {
    setHousingList (state, payload) {
      state.HousingList = payload.HousingList
    },
    setTotal (state, payload) {
      state.total = payload.total
    },
    setLeaseList (state, payload) {
      state.LeaseList = payload.LeaseList
    },
    setLeaseTotal (state, payload) {
      state.LeaseTotal = payload.LeaseTotal
    }
  },
  actions: {
    async getHousingList ({
      commit
    }, payload) {
      const res = await instance.get('/housing', {
        params: payload
      })
      if (res.data.code === 1) {
        commit('setHousingList', {
          HousingList: res.data.data.data
        })
        commit('setTotal', {
          total: res.data.data.total
        })
      }
    },
    async getLeaseList ({
      commit
    }, payload) {
      const res = await instance.get('/leases', {
        params: { ...payload, pid: 0 }
      })
      if (res.data.code === 1) {
        commit('setLeaseList', {
          LeaseList: res.data.data.data
        })
        commit('setLeaseTotal', {
          LeaseTotal: res.data.data.total
        })
      }
    }
  },
  modules: {}
}
